/******************************************************************************
 * * app_adaptor.c - implementation of function app adaptor
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "lv_watch.h"

#if USE_LV_WATCH_APP_ADAPTOR != 0

/*********************
*      INCLUDES
*********************/
#include <stdio.h>
#include "app_adaptor.h"

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 *  GLOBAL FUNCTION
 **********************/
void app_adaptor_get_weather_req(app_adaptor_weather_t * weather)
{
    static uint8_t dummy_read_count = 1;
    static char city[20] = "大连";

    if(0 == dummy_read_count) {
        weather->weather_id = WATCH_WEATHER_ID_NO_INFO;
    } else if(dummy_read_count >= 1) {
        weather->city = city;

        weather->lowest_temperature = 20;
        weather->highest_temperature = 25;
        weather->current_temperature = 23;
        weather->uv = 3;
        weather->aqi = 156;
        weather->weather_id = dummy_read_count - 1;

        if(dummy_read_count >= 15) {
            dummy_read_count = 99;
        }
    }

    dummy_read_count++;
}

char * app_adaptor_get_model_id(void)
{
    static char model[] = "ASR01";
    return model;
}

char * app_adaptor_get_version(void)
{
    static char version[50] = {};
    watch_modem_get_baseband_ver_req(version);
    //snprintf(version, 40, "\n%s\n%s", __DATE__, __TIME__);
    return version;
}

char * app_adaptor_get_cid_for_qrcode(void)
{
    static char cid[] = "1AS011830K6HWSJ0";
    return cid;
}

char * app_adaptor_get_cid_for_barcode(void)
{
    static char cid[] = "285602887311703072";
    return cid;
}

void app_adaptor_send_sos_info_req(void)
{
    // TBD
    return;
}

void app_adaptor_get_pedometer_info_req(app_adaptor_pedometer_record_t * record)
{
    record->step = 5600;
    record->kcal = 120;
    record->km = 4.5;
    #if USE_LV_WATCH_PEDOMETER != 0
    pedometer_update_steps(record->step);
    #endif
}

void app_adaptor_get_health_info_req(app_adaptor_health_info_t * health)
{
    health->heartrate = 110;
    health->bloodoxygen = 98;
    health->sleep = SLEEP_GOOD;
    health->pressure = 80;
}

void app_adaptor_set_alarm_bind(app_adaptor_set_alarm func)
{

}

void app_adaptor_shutdown_bind(app_adaptor_shutdown func)
{

}

void app_adaptor_get_activity_info_req(app_adaptor_activity_info_t * activity)
{
    uint32_t steps_wday[ACTIVITY_WDAY_CNT] = {5678, 1234, 12541, 8326, 0, 10000, 20465};
    uint32_t high_strength_wday[ACTIVITY_WDAY_CNT] = {12, 60, 35, 10, 8, 30, 20};
    uint32_t activity_hours_wday[ACTIVITY_WDAY_CNT] = {10, 5, 16, 12, 10, 8, 3};
    uint8_t active[ACTIVITY_OCLOCK_CNT] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};

    static uint32_t tick = 0;
    tick++;

    activity->steps_goal = 10000;  //steps
    activity->steps_today = 1273 + tick/2;
    for(uint8_t i = 0; i < ACTIVITY_WDAY_CNT; i++) {
        activity->steps_wday[i] = steps_wday[i];
    }

    activity->high_strength_goal = 30; //mins
    activity->high_strength_today = 1 + tick/60;
    for(uint8_t i = 0; i < ACTIVITY_WDAY_CNT; i++) {
        activity->high_strength_wday[i] = high_strength_wday[i];
    }

    activity->active_hours_goal = 12; //hours
    activity->active_hours_today = 2;
    for(uint8_t i = 0; i < ACTIVITY_WDAY_CNT; i++) {
        activity->active_hours_wday[i] = activity_hours_wday[i];
    }

    activity->calorie = 86 + tick/10; //kcal
    activity->distance = 1.04 + (double)tick/100; //km
    activity->stairs = 114.8 + (double)tick/10; //m

    for(uint8_t i = 0; i < ACTIVITY_OCLOCK_CNT; i++) {
        activity->active[i] = active[i];
    }
}

#endif /*USE_LV_WATCH_APP_ADAPTOR*/
